<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>导游列表</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/static/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/static/layuiadmin/style/admin.css" media="all">
    <style>
        #guide_ul li{
            margin-top: 15px;
        }
    </style>
</head>
<body>
<div id="aaa"></div>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header">导游列表</div>
                <div class="layui-card-body">
                    <div class="layui-form-item layui-form">

                        <!--<div class="layui-inline">-->
                            <!--<div class="layui-inline">-->
                                <!--<div class="layui-btn-group test-table-operate-btn">-->
                                    <!--<button class="layui-btn" data-type="addadmin">入住导游</button>-->
                                <!--</div>-->
                            <!--</div>-->
                        <!--</div>-->

                        <div class="layui-inline">
                            <label class="layui-form-label">姓名</label>
                            <div class="layui-input-block">
                                <input type="text" name="name" id="name" placeholder="请输入" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">手机</label>
                            <div class="layui-input-block">
                                <input type="text" name="guide_tel" id="guide_tel" placeholder="请输入" autocomplete="off" class="layui-input">
                            </div>
                        </div>

                        <div class="layui-inline">
                            <label class="layui-form-label">身份证号</label>
                            <div class="layui-input-block">
                                <input type="text" name="cardid" id="cardid" placeholder="请输入" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <div class="layui-btn-group test-table-operate-btn">
                                <button class="layui-btn" data-type="searchUserButton">
                                    <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                                </button>
                            </div>
                        </div>
                    </div>
                    <table class="layui-hide" id="test-table-operate" lay-filter="test-table-operate">
                    </table>
                    <script type="text/html" id="test-table-operate-barDemo">
                        <a class="layui-btn layui-btn-xs" lay-event="showDetail">详细信息</a>
                        <a class="layui-btn layui-btn-normal layui-btn-xs" id="showImg" lay-event="showImg">导游相册</a>
                        <!--{{# if(d.is_send==0){ }}-->
                        <!--<a class="layui-btn layui-btn-warm layui-btn-xs" lay-event="sendMerchant">发送商户账号</a>-->
                        <!--{{# } else { }}-->
                        <!--<a class="layui-btn layui-btn-disabled layui-btn-xs" lay-event="">已发送账号</a>-->
                        <!--{{# } }}-->
                        <a class="layui-btn layui-btn-green layui-btn-xs" lay-event="edit">修改</a>
                        <!--<a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="yesPass">修改相册</a>-->
                        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="guide_del">删除</a>
                    </script>
                </div>
            </div>
        </div>
    </div>
</div>

<div id="contentShow" style="display:none;padding: 30px;">
    <p id="consultation"></p>
</div>
<!--导游信息详情-->
<div id="userDetail" style="display: none;padding:20px;">
    <div class="userDetailCen">
        <ul id="guide_ul">
            <li>
                <p class="p-user">身份证号：<span id="idcardnum"></span></p>
            </li>
            <li>
                <p class="p-user">银行卡号：<span id="guide_card"></span></p>
            </li>
            <li>
                <p class="p-user">开户行：<span id="guide_open_bank"></span></p>
            </li>
            <li>
                <p class="p-user">持卡人姓名：<span id="guide_card_name"></span></p>
            </li>
            <li>
                <p class="p-user">导游休息日：<span id="guide_rest_time"></span></p>
            </li>
            <li>
                <p class="p-user">导游描述：<span id="guide_content"></span></p>
            </li>
            <li>
                <p class="p-user">导游标签：<span id="guide_tag"></span></p>
            </li>

            <li>
                <p class="p-user">导游身份证照片：</p>
                <img src="" id="guide_card_img1" style="width: 200px;height: 140px">
                <img src="" id="guide_card_img2" style="width: 200px;height: 140px;margin-left: 15px">
            </li>
            <li>
                <p class="p-user">导游证件照：</p>
                <img src="" id="guide_pic" style="width: 200px;height: 140px"/>
            </li>
        </ul>
    </div>
</div>

<script src="/static/layuiadmin/layui/layui.js"></script>
<script>
    layui.config({
        base: '/static/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index','form','table','laydate','set'], function(){
        $ = layui.jquery;
        var table = layui.table
            ,admin = layui.admin
            ,element = layui.element
            ,layer = layui.layer
            ,laydate = layui.laydate
            ,form = layui.form;

        table.render({
            elem: '#test-table-operate'
            ,url: "{:url('Merchant/guide')}"
            ,height: 'full-100'
            ,cols: [[
                {field:'guide_id',width:80,align:'center', title: 'ID'}
                ,{field:'name',align:'center',title: '姓名'}
                ,{field:'guide_tel',align:'center',title: '手机号'}

                ,{field:'guide_money', align:'center', title: '导游价格'}

                ,{field:'examine_time', align:'center', title: '入住时间'}
                ,{align:'center',width:450, title: '操作', toolbar: '#test-table-operate-barDemo'}
            ]]
            ,page:true
            ,limit:20
        });

        form.render(null,'component-form-group');

        laydate.render({
            elem: '#search_time'
        });

        //监听工具条
        table.on('tool(test-table-operate)', function(obj){
            var data = obj.data;
            if(obj.event === 'showDetail'){
                var loading = layer.load(1, {
                    shade: [0.1,'#fff'] //0.1透明度的白色背景
                });
                var guide_id = data.guide_id;
                $.ajax({
                    url: "{:url('Merchant/guideInfoDetail')}",
                    type: 'post',
                    dataType: 'json',
                    data: {guide_id:guide_id},
                    success: function(data){
                        layer.close(loading);
                        if (data.code === 0) {
                            if(data.data.cardid==""){
                                $('#idcardnum').html('未设置');
                            }else{
                                $('#idcardnum').html(data.data.cardid);
                            }
                            if(data.data.guide_card ==""){
                                $('#guide_card').html('未设置');
                            }else{
                                $('#guide_card').html(data.data.guide_card);
                            }
                            if(data.data.guide_open_bank==''){
                                $('#guide_open_bank').html('未设置');
                            }else{
                                $('#guide_open_bank').html(data.data.guide_open_bank);
                            }
                            if(data.data.guide_card_name==''){
                                $('#guide_card_name').html('未设置');
                            }else{
                                $('#guide_card_name').html(data.data.guide_card_name);
                            }
                            if(data.data.guide_rest_time == ''){
                                $('#guide_rest_time').html('未设置');
                            }else{
                                $('#guide_rest_time').html(data.data.guide_rest_time);
                            }

                            if(data.data.guide_content == ''){
                                $('#guide_content').html('未设置');
                            }else{
                                $('#guide_content').html(data.data.guide_content);
                            }
                            if(data.data.guide_tag == ''){
                                $('#guide_tag').html('未设置');
                            }else{
                                $('#guide_tag').html(data.data.guide_tag);
                            }
                            //处理身份证图片
                            var img_src = data.data.guide_card_img;
                            var img_src_arr = img_src.split(',');
                            $('#guide_card_img1').attr('src',img_src_arr[0]);
                            $('#guide_card_img2').attr('src',img_src_arr[1]);
                            //导游照片
                            $('#guide_pic').attr('src',data.data.guide_pic);
                            var userDetailModal = layer.open({
                                title:'导游信息详情'
                                ,type: 1
                                ,shadeClose: true
                                ,area:['800px']
                                ,content: $('#userDetail')
                            });
                        }else{
                            layer.msg('获取信息失败',{icon:2,time:1000});
                        }


                    }
                })
            } else if(obj.event === 'showImg'){
                $.ajax({
                    url: "{:url('Merchant/guideImage')}",
                    type: 'post',
                    dataType: 'json',
                    data: {id:data.guide_id},
                    success: function(msg){
                        if (msg.code == 0) {
                            var arr  = msg.data;
                            let img_src_arr = [];
                            for (var i in arr) {
                                img_src_arr.push(arr[i].img_path)
                            }
                            console.log(img_src_arr);
                            var img_src_data = {};
                            img_src_data.title = '导游相册图片';
                            img_src_data.id = data.id;
                            img_src_data.start = 0;
                            img_src_data.data =[];

                            var src = {};

                            for(var i=0;i<img_src_arr.length;i++){
                                src = {};
                                var num = i+1;
                                src.alt = '导游证件照片'+ num;
                                src.pid = i;
                                src.src = img_src_arr[i];
                                src.thumb = img_src_arr[i];
                                console.log(src);
                                img_src_data.data.push(src);
                            }
                            layer.photos({
                                photos: img_src_data
                                ,anim: 5 //0-6的选择，指定弹出图片动画类型，默认随机（请注意，3.0之前的版本用shift参数）
                            });
                        }else{
                            layer.msg(msg.message,{time:1000});
                        }
                    }
                });

            } else if(obj.event === 'guide_del'){
                layer.confirm('确认删除"' + data.name + '"吗？', function(index){
                    var loading = layer.load(1, {
                        shade: [0.1,'#fff'] //0.1透明度的白色背景
                    });
                    $.ajax({
                        url: "{:url('Merchant/delGuide')}",
                        type: 'post',
                        dataType: 'json',
                        data: {id:data.guide_id},
                        success: function(msg){
                            layer.close(loading);
                            if (msg.code == 0) {
                                obj.del();
                                layer.close(index);
                            }else{
                                layer.msg(msg.message,{icon:2,time:1000});
                            }
                        }
                    });
                });
            } else if(obj.event === 'sendMerchant'){
                var loading = layer.load(1, {
                    shade: [0.1,'#fff'] //0.1透明度的白色背景
                });
                var guide_id = data.guide_id;
                var guide_tel = data.guide_tel;
                var cardid = data.cardid;
                var rename = data.name;
                $.ajax({
                    url: "{:url('Merchant/sendGuideMerchant')}",
                    type: 'post',
                    dataType: 'json',
                    data: {guide_id:guide_id,guide_tel:guide_tel,cardid:cardid,rename:rename},
                    success: function(data){

                    }
                });
            }else if(obj.event === 'edit'){
                window.location.href="{:url('Merchant/editGuide')}?id=" + data.guide_id;
            }

        });

        var $ = layui.$, active = {
            addadmin: function() {
                window.location.href="{:url('Merchant/guideAdd')}";
            },
            searchUserButton:function(){
                var name  = $('#name').val();
                var tel = $('#guide_tel').val();
                var cardid = $('#cardid').val();

                table.reload('test-table-operate', {
                    where: {
                        name:name,
                        guide_tel: tel,
                        cardid:cardid
                    }
                    ,page: {
                        curr: 1 //重新从第 1 页开始
                    }
                });
                //return false;
            }
        };
        //绑定点击事件
        $('.test-table-operate-btn .layui-btn').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

    });

</script>


</body>
</html>